import 'package:tiktokadult/hj_model/mine/base_list_res.dart';
import 'package:tiktokadult/hj_model/video_model.dart';
import 'package:tiktokadult/hj_utils/http_manager.dart';

import '../../hj_model/actress_info.dart';
import '../../hj_model/actress_model.dart';
import '../../hj_model/user/mine_video.dart';

class ActressService {
  //获取女优/网黄列表
  static Future<BaseListResEntity<ActressInfo>?> getActressList({
    required int pageNumber,
    required int pageSize,
    Map<String, dynamic>? filterMap,
  }) async {
    Map<String, dynamic> param = {
      'pageNumber': pageNumber,
      'pageSize': pageSize,
    };
    if (filterMap?.isNotEmpty == true) {
      param.addAll(filterMap!);
    }
    param.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByGET(
      '/actress/list',
      param: param,
    );
    if (result.isSuccess) {
      BaseListResEntity<ActressInfo> value = BaseListResEntity.fromJson(result.data, (v) => ActressInfo.fromJson(v));
      return value;
    }
    return null;
  }

  //获取全部女优-top20
  static Future<BaseListResEntity<ActressInfo>?> actressTop() async {
    final result = await httpManager.fetchResponseByGET(
      '/actress/top',
      param: {},
    );
    if (result.isSuccess) {
      BaseListResEntity<ActressInfo> value = BaseListResEntity.fromJson(result.data, (v) => ActressInfo.fromJson(v));
      return value;
    }
    return null;
  }

  //获取全部女优-top20
  static Future<ActressFilterResp?> actressSearchCond() async {
    final result = await httpManager.fetchResponseByGET(
      '/actress/searchCond',
      param: {},
    );
    if (result.isSuccess) {
      return ActressFilterResp.fromJson(result.data);
    }
    return null;
  }

  //获取女优/网黄列表
  static Future<ActressModel?> getActressInfo({
    required String? id,
  }) async {
    final param = {
      'id': id,
    };
    param.removeWhere((k, v) => v == null);
    final result =
        await httpManager.fetchResponseByGET('/actress/info', param: param, jsonTransformation: (json) => ActressModel.fromJson(json));
    if (result.isSuccess) {
      return result.data;
    }
    return null;
  }

  //sortType 0 最多播放; 1 最新添加; 2 最高人气
  //vidType 0 影视; 1 图集
  static Future<MineCollect?> fetchActressWorksById(String id, {int page = 1, int size = 20, int? vidType, int? sortType}) async {
    final param = <String, dynamic>{
      'pageNumber': page,
      'pageSize': size,
      'vidType': vidType,
      'sortType': sortType,
      'id': id,
    };
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByGET('/actress/vid/list',
        param: param, jsonTransformation: (json) => MineCollect<VideoModel>.fromJson(json));
    return result.data;
  }
}
